package com.example.geckohurricanes;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
	

public class RegisterActivity extends Activity {
    public EditText name, pass, id;
    
    String user, password;
	DatabaseHandler db;
	
	@Override
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        db = new DatabaseHandler(this);
        
        setContentView(R.layout.register);
        name = (EditText) findViewById(R.id.reg_username);
        pass = (EditText) findViewById(R.id.reg_password);
        id =   (EditText) findViewById(R.id.reg_email);
        
        TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
        Button register = (Button) findViewById(R.id.btnRegister);
        
        // Listening to Login Screen link
        loginScreen.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View arg0) {
                                // Closing registration screen
                // Switching to Login Screen/closing register screen
                finish();
            }
        });
        
        //Register the user and return to login page
        register.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		user = name.getText().toString();
        		password = pass.getText().toString();
        		db.addContact(new Contact(user, password));
        		Toast.makeText(getApplicationContext(), "Registration Successful", Toast.LENGTH_SHORT).show();
        		db.close();
        		Intent i = new Intent(getApplicationContext(), LoginActivity.class);
        		startActivity(i);
        		finish();
        	}
        });
        
	}
}
        
         
        
    

